package org.tech4j.common.utils.path;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @program: tech4j-common
 * @description:
 * @author: YuKai Fan
 * @create: 2025/3/2 22:08
 **/
public class PathMatchUtils {

    private static final Tech4jPathMatcher MATCHER = new Tech4jAntPathMatcher();

    /**
     * replace url {id} to real param.
     *
     * @param path the total path
     * @param regex the regex content
     * @param replacement the replacement content
     * @return the string
     */
    public static String replaceAll(final String path, final String regex, final String replacement) {
        return path.replaceAll(Pattern.quote(regex), Matcher.quoteReplacement(replacement));
    }

    /**
     * Match boolean.
     *
     * @param matchUrls the path pattern
     * @param realPath the real path
     * @return the boolean
     */
    public static boolean match(final String matchUrls, final String realPath) {
        return MATCHER.match(matchUrls, realPath);
    }
}
